package com.xiaomage.ViewDraw16

import android.content.Context
import android.graphics.*
import android.view.View

/**
 * Created by Administrator on 2018/1/23.
 */
class MyView(context: Context):View(context) {
    private var paint= Paint();
    private var bitmap=BitmapFactory.decodeResource(resources,R.drawable.cat)
    private var alphaBitmap=bitmap.extractAlpha()
    init {
        setLayerType(LAYER_TYPE_SOFTWARE,null)
    }

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        val width=500
        val height=width*alphaBitmap.height/alphaBitmap.width
        paint.color= Color.RED
        //设置内外发光
        paint.maskFilter = BlurMaskFilter(10f,BlurMaskFilter.Blur.NORMAL)
        canvas.drawBitmap(alphaBitmap,null,
        Rect(10,10,width,height),paint)

        paint.color= Color.GREEN
        canvas.drawBitmap(alphaBitmap,null,
                Rect(10,height+10,width,height*2),paint)

        paint.maskFilter=null
        canvas.drawBitmap(bitmap,null,
                Rect(0,0,width,height),paint)
        canvas.drawBitmap(bitmap,null,
                Rect(0,height,width,height*2),paint)
    }
}